import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        title:'', // 网站head标题
        menu:'', // 保存按钮状态
        index:'', // 保存导航 选中状态
    },
    mutations: {
       setTitle(state,title){
            sessionStorage.setItem('title',title);
            state.title = title;
       },
       setMenu(state,menu){
            sessionStorage.setItem('menu',menu);
            state.menu = menu;
       },
       setIndex(state,index){
            index = index.toString();
            sessionStorage.setItem('index',index);
            state.index = index;
       }
    },
    getters:{
       getTitle(state){
           if(!state.title){
                state.title = sessionStorage.getItem('title');
           }
           return state.title;
       },
       getMenu(state){
            if(!state.menu){
                    state.menu = sessionStorage.getItem('menu');
            }
            return state.menu;
        },  
        getIndex(state){
            if(!state.index){
                    state.index = sessionStorage.getItem('index');
            }
            return state.index;
        }
    }
})

export default store;
